Param(
    [Parameter(Mandatory=$true)][string]$Url
)

Write-Output "Checking URL: $Url"

function Print-Resp($resp) {
    try { Write-Output ("StatusCode: " + $resp.StatusCode) } catch {}
    try { Write-Output ("ContentType: " + $resp.Headers['Content-Type']) } catch {}
    try { Write-Output ("ContentLength: " + $resp.Headers['Content-Length']) } catch {}
    try { Write-Output ("Server: " + $resp.Headers['Server']) } catch {}
    try { Write-Output ("Accept-Ranges: " + $resp.Headers['Accept-Ranges']) } catch {}
}

try {
    $resp = Invoke-WebRequest -Uri $Url -Method Head -TimeoutSec 10
    Write-Output "HEAD request succeeded."
    Print-Resp $resp
} catch {
    Write-Output ("HEAD failed: " + $_.Exception.Message)
    try {
        $resp = Invoke-WebRequest -Uri $Url -Method Get -TimeoutSec 10 -MaximumRedirection 2
        Write-Output "GET request succeeded."
        Print-Resp $resp
    } catch {
        Write-Output ("GET failed: " + $_.Exception.Message)
    }
}